import { defineStore } from 'pinia'
import { computed, ref } from 'vue'

/**
  1. id: 仓库的名称(仓库的唯一标识)
  2. storeSetup: 类似于vue中的setup函数, 用于处理仓库的所有业务
  3. options?: 当前仓库的配置项
 */
export const useCountStore =  defineStore('count', ()=>{
  // state
  const count = ref(100)
  const car = ref('宝马')
  // getters
  const dbCount = computed(()=> count.value * 2)
  // mutations
  const updateCount = (num: number)=> count.value += num
  // actions
  const asyncUpdateCount = () => {
    setTimeout(()=>{
       count.value++
    }, 1000)
  }
  return {count, car, dbCount, updateCount, asyncUpdateCount}
})